<?php
namespace Home\Controller;
use Common\Controller\CommonController;
class ProductController extends CommonController {
    public function index(){
    	//根据左侧导航left 传过来的pid
		$where["tid"]=I("pid","");
		$where["status"]=1;
		$where["position"]=4;
		if(!empty($where["tid"])){
			$count      = M("Ptype")->where($where)->count();// 查询满足要求的总记录数
			$Page       = new \Think\Page($count,4);// 实例化分页类 传入总记录数和每页显示的记录数(25)
			$show       = $Page->show();// 分页显示输出// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			$list=M("Product")->where($where)->order("add_time desc")->limit($Page->firstRow.','.$Page->listRows)->select();
		}else{
			unset($where);
			$title=I("title","");
			$where['title']=array('like','%'.$title.'%');
			$where["status"]=1;
			$where["position_id"]=4;
			$count      = M("Ptype")->where($where)->count();// 查询满足要求的总记录数
			$Page       = new \Think\Page($count,4);// 实例化分页类 传入总记录数和每页显示的记录数(25)
			$show       = $Page->show();// 分页显示输出// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			$list=M("Product")->where($where)->order("add_time desc")->limit($Page->firstRow.','.$Page->listRows)->select();
		}
		$this->assign('page',$show);
		$this->assign("list",$list);
    	$this->display();
    }
    public function details(){
    	$where["id"]=I("id","");
    	$where["status"]=1;
    	if(!empty($where["id"])){
    		$list=M("Product")->where($where)->find();
    	}
    	$this->assign("list",$list);
    	$this->display();
    }
}